package com.kk.convert;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.convert.ConverterRegistry;
import cn.hutool.core.util.CharsetUtil;

import java.util.concurrent.TimeUnit;

/**
 * the type of advance
 *
 * <p>
 * .
 *
 * @author 王志强
 * @date 2022-03-21
 */
public class Client {
    public static void main(String[] args) {

        long[] b = {1, 2, 3, 4, 5};
        //long数组转int数组
        System.out.println(Convert.toIntArray(b));

        String data = "2022/02/22 08:00:00";
        //String转日期对象
        System.out.println(Convert.toDate(data));

        Object[] o = {"a", "你", "好", "", 1};
        //Object转为List
        System.out.println(Convert.toList(o));


        String ss = "我是一个小小的可爱的字符串";
        //16进制转换,必须传入编码方式
        String toHex = Convert.toHex(ss, CharsetUtil.CHARSET_UTF_8);
        String hexToStr = Convert.hexToStr(toHex, CharsetUtil.CHARSET_UTF_8);

        //unicode转换
        String toUnicode = Convert.strToUnicode(ss);
        String unicodeToStr = Convert.unicodeToStr(toUnicode);


        String a = "我不是乱码";
        //编码转换,,,注意 经过测试，UTF-8编码后用GBK解码再用GBK编码后用UTF-8解码会存在某些中文转换失败的问题。
        String convertCharset = Convert.convertCharset(a, CharsetUtil.UTF_8, CharsetUtil.GBK);
        String convertCharset1 = Convert.convertCharset(convertCharset, CharsetUtil.GBK, CharsetUtil.UTF_8);

        long t = 4535345;
        //时间单位转换
        long minutes = Convert.convertTime(t, TimeUnit.MILLISECONDS, TimeUnit.MINUTES);


        double money = 67556.32;
        //金额大小写转换: 转换为大写只能精确到分（小数点后两位），之后的数字会被忽略。
        String digitToChinese = Convert.digitToChinese(money);
        //转中文
        String s = Convert.numberToChinese(money, false);


        //类的灵活转换
        int myData = 3423;
        ConverterRegistry converterRegistry = ConverterRegistry.getInstance();
        String result = converterRegistry.convert(String.class, myData);


    }
}
